package eo.builder;

import java.io.IOException;
import java.net.URL;
import java.util.List;

import eo.builder.util.IterationStep;

/**
 * Visitor for resources inside a {@link URL}.
 * 
 * @author takeshi
 * 
 */
public interface URLVisitor {

	/**
	 * Returns wheter or not this {@link URLVisitor} can handle the specified
	 * {@link URL}
	 * 
	 * @param url
	 *            the {@link URL} to check
	 * @return <code>true</code> if this {@link URLVisitor} can handle this
	 *         {@link URL}
	 */
	boolean canResolve(URL url);

	/**
	 * Checks if the given resource can be found inside the given URL.
	 * 
	 * @param resourceName
	 *            the resource name to look for
	 * @param url
	 *            the url that contains the resource
	 * @return <code>true</code> if the resource is inside the url
	 * @throws IOException
	 *             if an exception occurs
	 */
	boolean isResourcePresent(String resourceName, URL url) throws IOException;

	/**
	 * List resources inside the given url that matches the given regex pattern.
	 * The pattern is case sensitive.
	 * 
	 * @param root
	 *            the {@link URL}
	 * @param pattern
	 *            the regex pattern
	 * @return {@link List} of {@link String}
	 * @throws IOException
	 *             if an exception occurs
	 */
	List<String> listMatchingResources(URL root, String pattern)
			throws IOException;

	/**
	 * Iterates through the resources in the given {@link URL}
	 * 
	 * @param iteration
	 *            the {@link IterationStep} to execute
	 * @param url
	 *            the root {@link URL}
	 * @throws IOException
	 *             if an exception occurs
	 */
	void iterate(IterationStep<String> iteration, URL url) throws IOException;

}
